package com.example.imtoken.modules.main.wallet.manage.wallet

import androidx.recyclerview.widget.LinearLayoutManager
import com.blankj.utilcode.util.StringUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.example.imtoken.R
import com.example.imtoken.core.OnAdapterClickActivityListener
import com.example.imtoken.core.OnSetDefHomeWalletListener
import com.example.imtoken.databinding.ItemManageBinding
import com.example.imtoken.entitys.app.ManageWalletsEntity

class ManageWalletAdapter(layoutResId: Int, val type: Int) :
    BaseQuickAdapter<ManageWalletsEntity, BaseDataBindingHolder<ItemManageBinding>>(layoutResId) {
    override fun convert(
        holder: BaseDataBindingHolder<ItemManageBinding>,
        item: ManageWalletsEntity
    ) {
        holder.dataBinding?.item = item
        val adapter = WalletAdapter(type)
        val layoutManager = object : LinearLayoutManager(context) {
            override fun canScrollVertically(): Boolean {
                return false
            }
        }
        holder.dataBinding?.rvManageWallet?.layoutManager = layoutManager
        holder.dataBinding?.rvManageWallet?.adapter = adapter
        adapter.setList(item.wallets)
        adapter.setOnItemClickListener { _, _, position ->
            if (adapter.data[position].name != StringUtils.getString(R.string.addToken)) {
                if (type == 1) {
                    onSetDefHomeWalletListener?.defAddress(adapter.data[position].key)
                } else {
                    onAdapterClickActivityListener?.click(adapter.data[position].key)
                }
            } else {
                onAdapterClickActivityListener?.click(null)
            }
        }
    }

    private var onSetDefHomeWalletListener: OnSetDefHomeWalletListener? = null

    fun setOnSetDefHomeWalletListener(onSetDefHomeWalletListener: OnSetDefHomeWalletListener) {
        this.onSetDefHomeWalletListener = onSetDefHomeWalletListener
    }

    private var onAdapterClickActivityListener: OnAdapterClickActivityListener? = null
    fun setOnAdapterClickActivityListener(onAdapterClickActivityListener: OnAdapterClickActivityListener) {
        this.onAdapterClickActivityListener = onAdapterClickActivityListener
    }

}